import HandleMysql
from pytools import mysqltool
import _mysql, _mysql_exceptions
from datetime import date, timedelta


def connect_to_localhost(db='zhaoxiang'):
    host = 'localhost'
    port = 3306
    user = 'root'
    passwd = 'zhaoxiang'

    dbh = _mysql.connect(host, user, passwd, db, port)
    return dbh

def getDBConnect():
    conn = HandleMysql('10.5.20.16','58885','zhaoxiang_ro','WBVQXMjbTvdDETlgW2','dbwww58com_58_stats')
    conn.connect()
    return conn

def get_info(q):
    info = {}
    conn = mysqltool.connect_to_58_stats()
    r = mysqltool.query(conn, q)
    conn.close()
    return r

if __name__ == '__main__':
    #conn=getDBConnect()
    sql='select cate_id, cate1, cate2, channel_id from belong_cate where cate3_id=0 and cate_id=1'
    results=get_info(sql)
   # results=conn.get_results(sql
    for r in results:
        print(r.count(''))
    print('_'.join(['cate','local',str(20140214)]))